/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-08-05     CICFE       the first version
 */
#ifndef APPLICATIONS_DEVICE_KEY_H_
#define APPLICATIONS_DEVICE_KEY_H_

#include <stdint.h>
#include "drv_common.h"
/*------------------------------------------------------------------------------
 Section: Macro Definitions
 ------------------------------------------------------------------------------*/
#define KEY_FIFO_SIZE   10

#define KEY1    (GET_PIN(I, 8))
#define KEY2    (GET_PIN(C, 13))
#define KEY3    (GET_PIN(H, 4))

/*------------------------------------------------------------------------------
 Section: Type Definitions
 ------------------------------------------------------------------------------*/
/* 按键FIFO用到变量 */
typedef struct
{
    uint8_t Buf[KEY_FIFO_SIZE];     /* 键值缓冲区 */
    uint8_t Read;                   /* 缓冲区读指针1 */
    uint8_t Write;                  /* 缓冲区写指针 */
    uint8_t Read2;                  /* 缓冲区读指针2 */
}KEY_FIFO_T;

typedef enum
{
    KEY_NONE = 0,           /* 0 表示按键事件 */

    KEY_1_DOWN,             /* 1键按下 */
    KEY_1_UP,               /* 1键弹起 */
    KEY_1_LONG,             /* 1键长按 */

    KEY_2_DOWN,             /* 2键按下 */
    KEY_2_UP,               /* 2键弹起 */
    KEY_2_LONG,             /* 2键长按 */

    KEY_3_DOWN,             /* 3键按下 */
    KEY_3_UP,               /* 3键弹起 */
    KEY_3_LONG,             /* 3键长按 */

    KEY_4_DOWN,             /* 4键按下 */
    KEY_4_UP,               /* 4键弹起 */
    KEY_4_LONG,             /* 4键长按 */

    KEY_5_DOWN,             /* 5键按下 */
    KEY_5_UP,               /* 5键弹起 */
    KEY_5_LONG,             /* 5键长按 */

    KEY_6_DOWN,             /* 6键按下 */
    KEY_6_UP,               /* 6键弹起 */
    KEY_6_LONG,             /* 6键长按 */

    KEY_7_DOWN,             /* 7键按下 */
    KEY_7_UP,               /* 7键弹起 */
    KEY_7_LONG,             /* 7键长按 */

    KEY_8_DOWN,             /* 8键按下 */
    KEY_8_UP,               /* 8键弹起 */
    KEY_8_LONG,             /* 8键长按 */

    /* 组合键 */
    KEY_9_DOWN,             /* 9键按下 */
    KEY_9_UP,               /* 9键弹起 */
    KEY_9_LONG,             /* 9键长按 */

    KEY_10_DOWN,            /* 10键按下 */
    KEY_10_UP,              /* 10键弹起 */
    KEY_10_LONG,            /* 10键长按 */
}KEY_ENUM;

/*------------------------------------------------------------------------------
 Section: Function Definitions
 ------------------------------------------------------------------------------*/
void Key_Thread(void *arg);
void InitKey(void);
uint8_t GetKey(void);

#endif /* APPLICATIONS_DEVICE_KEY_H_ */
